package cn.wolfcode;

import cn.wolfcode.web.interceptor.CheckLoginInterceptor;
import cn.wolfcode.web.interceptor.CheckPermissionInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("cn.wolfcode.mapper")
public class App implements WebMvcConfigurer {
    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;
    @Autowired
    private CheckPermissionInterceptor checkPermissionInterceptor;

    // 配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录检查
        registry.addInterceptor(checkLoginInterceptor)
                .addPathPatterns("/**") // 对资源拦截
                .excludePathPatterns("/userLogin","/login.html", "/css/**","/js/**");// 对哪些资源起排除作用
        // 权限拦截
        registry.addInterceptor(checkPermissionInterceptor)
                .addPathPatterns("/**") // 对资源拦截
                .excludePathPatterns("/userLogin","/login.html", "/css/**","/js/**");// 对哪些资源起排除作用
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
